<?php

include _ITSTOCK_INCLUDE_DIR_.'html_set_location.inc.php';

itstock_structure($structure, 'cpu');
$edit = false;

if(isset($_POST['id'])) {
    $structure['where'][0] = sprintf("`%s`.`id`='%s'", $structure['table'], itstock_decode($_POST['id']));
    $edit = itstock_search_all($structure);
}

?><b><?php echo (!$edit?'New ':'')?>CPU</b>
  <br><br><br>
<form class="save" action="store.php?type=cpu" method="POST" id="form_cpu" autocomplete="off">
  <input type="hidden" value="<?php echo ($edit?itstock_encode($structure['data'][0]['id']):'')?>" id="id" name="id">
  <table>
    <tr>
      <td><label>CPU Label:</label></td>
      <td><input type="text" autofocus name="cpu" style="width: 200px" value="<?php echo ($edit?$structure['data'][0]['cpu']:'')?>" required placeholder="CPU"></td>
    </tr>
    <tr>
      <td><label>Choose a Location:</label></td>
      <td>
        <img id="location_btn" onclick="itstock_locations('locations');" src="img/search.png" title="Select Location" />
        <input type="text" value="<?php echo ($edit?'1':'');?>" style="display:none;" id="location_set" required>
        <img style="float:right;" onclick="itstock_locations('warehouses');" src="img/warehouse.png" title="Move to Warehouse" />
      </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td id="location_info">
      <?php
        if($edit) {
          if(!is_null($structure['data'][0]['cpu_location_id'])) {
            $lid = &$structure['data'][0]['cpu_location_id'];
            $ltype = 'location';
          } else if(!is_null($structure['data'][0]['cpu_warehouse_id'])) {
            $lid = &$structure['data'][0]['cpu_warehouse_id'];
            $ltype = 'warehouse';
          }
          itstock_page_set_location(itstock_encode($lid), $ltype, array('location' => 'cpu_location_id', 'warehouse' => 'cpu_warehouse_id'));
        }
        if(isset($_POST['lid']) && isset($_POST['ltype'])) {
          itstock_page_set_location($_POST['lid'], $_POST['ltype'], array('location' => 'cpu_location_id', 'warehouse' => 'cpu_warehouse_id'));
        }
      ?>
      </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><br><input type="submit" value="Save" style="margin-right: 100px;"><input type="reset" value="Reset"></td>
    </tr>
  </table>
</form>
